// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import BaseView from "../base/BaseView";
import StockListComponent from "../base/components/StockListComponent";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends BaseView {

    @property(cc.Prefab)
    stockListPrefab: cc.Prefab = null;

    @property(cc.Node)
    stockListLayer: cc.Node = null;

    stockListComp: StockListComponent = null;

    _stocks: any = null;

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        let node = cc.instantiate(this.stockListPrefab);
        this.stockListLayer.addChild(node);
        this.stockListComp = node.getComponent(StockListComponent);
    }

    protected onEnable(): void {
        cc.director.on('SelectStockEvent', this.onSelectStockEvent, this);
    }

    protected onDisable(): void {
        cc.director.off('SelectStockEvent', this.onSelectStockEvent, this);
    }

    onSelectStockEvent (selectIndex) {
        this.createDialog(BaseView.Views.StockInfoView, {stocks: this._stocks, selectIndex: selectIndex} );
    }

    show (stocks) {
        super.show(stocks);
        this.stockListComp.setData(stocks);
        this._stocks = stocks;
    }

    // update (dt) {}
}
